#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
class ThumbnailBarWidget;
class DicomImageView;
class QGridLayout;
class RadiomicsAlgorithm;
class QActionGroup;
class SeriesInstance;
class DicomImageLabel;
class QElapsedTimer;

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    enum ProcessStage {
        PS_NoSeed,
        PS_SeedChoosing,
        PS_SeedOk,
        PS_Segmenting,
        PS_SegmentOk,
        PS_SegmentFailed,
        PS_Extracting,
        PS_ExtractOk,
        PS_ExtractFailed,
        PS_Predicting,
        PS_PredictOk,
        PS_PredictFailed,
    };

    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

signals:
    void currentViewChanged(DicomImageView *view);

public slots:
    // menu Start
    void on_actionLoad_Images_triggered();
    void on_actionAppend_Images_triggered();
    void on_actionLoad_Prognostic_triggered();
    void on_actionSave_Prognostic_triggered();
    void on_actionQuit_triggered();

    // menu Process
    void on_actionChoose_Seed_triggered(bool checked);
    void on_actionSegment_triggered();
    void on_actionExtract_triggered();
    void on_actionPredict_triggered();
    void on_actionRun_All_triggered();
    void on_actionStop_triggered();

    // menu Examine
    void on_actionResult_triggered();
    void on_actionReport_triggered();
    void on_actionLog_File_triggered();

    // menu Settings
    void on_actionReport_Format_triggered();
    void on_actionAuto_Email_triggered();

    // menu View
    void on_actionMPR_toggled(bool checked);
    void on_actionTumor_triggered(bool checked);

    // menu Help
    void on_actionManual_PDF_triggered();
    void on_actionAbout_Radiomics_triggered();

protected slots:
    void updateAlgoOptions();
    void onSeedChoosing(int x, int y, int z, int val, DicomImageView *view);
    void onSeedFinished(bool ok);
    void onSeedUiChanged();

    void onSeriesInserted(SeriesInstance *series);
    void onImageDoubleClicked(DicomImageLabel *label);
    void onImageChanged(DicomImageLabel *label);

    void onViewClicked(DicomImageView *view);
    void onViewDoubleClicked(DicomImageView *view);

    void onSegmentFinished(bool ok, const QString &msg);
    void onExtractFinished(bool ok, const QString &msg);
    void onPredictFinished(bool ok, const QString &msg);

private:
    void init();
    inline void disableUi(bool yes);
    void updateUiButtons();
    void loadImagesFromDir(const QString &dirStr);
    void logInstance();

    void doSegment();
    void doExtract();
    void doPredict();

    Ui::MainWindow *ui;
    ThumbnailBarWidget *thumbnailBar;
    DicomImageView *xyView;
    DicomImageView *xzView;
    DicomImageView *yzView;
    QGridLayout *viewLayout;
    DicomImageView *currentView;
    RadiomicsAlgorithm *algo;
    ProcessStage stage;
    double svmScore;

    QElapsedTimer *eTimer;
    bool runAll;

    QActionGroup *segmGrp;
    QActionGroup *extrGrp;
    QActionGroup *predGrp;

    bool viewMaximised;
    bool mouseSeed;
};

#endif // MAINWINDOW_H
